#ifndef LOG_H_
#define LOG_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <dirent.h>
#include <stdarg.h>
#include <errno.h>
#include <assert.h>
#include <stdio.h>
#include "util.h"

struct log_t;

#define ELogRotator_Size 1
#define ELogRotator_Hour 2
#define ELogRotator_Date 3

#define ELogLevel_Fatal 0
#define ELogLevel_Error 1
#define ELogLevel_Warn 2
#define ELogLevel_Debug 3
#define ELogLevel_Trace 4

#define MAX_LOG_NAME_LEN 1024
#define MAX_LOG_BUFFER_LEN 1024
#define MAX_LOG_SIZE_ROTATE_COUNT 10

/*
*   log_rotator_type: ELogRotator_*
*   log_name: log file name
*   args: when ELogRotator_Size, max file size
*/
struct log_t* log_init(int log_rotator_type, int log_level, const char* log_name, int args);

int log_release(struct log_t* log);

int log_write(struct log_t* log,
		int level, 
		struct timeval* now, 
		const char* file_name,
		int line_number,
		const char* function_name,
		char* fmt, ...);

int log_set_level(struct log_t* log, int log_level);

/*
*  no thread safe
*  need to guard by yourself
*/
#define LOG(log, level, now, fmt, ...) \
	do { log_write(log, level, now, __FILE__, __LINE__, __FUNCTION__, fmt, ##__VA_ARGS__);  } while(0)

#ifdef __cplusplus
}
#endif

#endif // LOG_H_

